package com.xbongbong.rule.symbol;

import com.alibaba.fastjson.JSONArray;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.rule.symbol.base.AbstractSymbol;
import com.xbongbong.saas.constant.StringConstant;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Objects;

/**
 * 等于任意一个判断
 * 适用类型:单选/下拉/成员单选/部门单选/阶段推进器
 *
 * @author zheng.li
 **/
public class InSymbol extends AbstractSymbol {
    @Override
    public boolean operation() {
        if (StringUtil.isEmpty(value.toString()) || conditionValueList.isEmpty()) {
            return false;
        }
        if (attr.contains(FieldTypeEnum.SUB_FORM.getEsalias()) && attr.contains(StringConstant.POINT)){
            //子表单
            JSONArray arrayValue = factJson.getJSONArray(attr);
            if (CollectionsUtil.isNotEmpty(arrayValue)){
                return CollectionsUtil.isNotEmpty(CollectionUtils.intersection(arrayValue, conditionValueList));
            }
        }else {
            //其他
            return conditionValueList.stream().anyMatch(o -> Objects.equals(o, value));
        }
        return false;
    }
}
